package com.espeaker.sdk.api;

import android.os.Handler;

import com.espeaker.sdk.Constants;
import com.espeaker.sdk.ESpeakerParameters;
import com.espeaker.sdk.utils.Base64Util;

public class GoldApi  extends MiaoApi {
	/*
	 * 语音提交
	 */
	public void audioSubmit(final String user_id,final String phoneNum,final int tiku_type,final String tiku_title,
			final int audio_length,final byte[] audio, final Handler handler) {
		//handler.obtainMessage(100024, (int)(System.currentTimeMillis() / 1000)+"进入提交").sendToTarget();
		new Thread() {
			@Override
			public void run() {
				try {
					//handler.obtainMessage(100024, (int)(System.currentTimeMillis() / 1000)+"进入线程").sendToTarget();
					String str_audio = Base64Util.encodeStr(audio);
					//String str_audio = new String(audio);
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", user_id+"",true);
					params.add("phone_number", phoneNum,true);
					params.add("tiku_type", tiku_type+"",true);
					params.add("tiku_title", tiku_title,true);
					params.add("audio_length", audio_length+"",true);
					params.add("audio", str_audio,false);
					//handler.obtainMessage(100024, (int)(System.currentTimeMillis() / 1000)+"开始提交").sendToTarget();
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_AUDIO_SUBMIT, params,1);
					//handler.obtainMessage(100024, (int)(System.currentTimeMillis() / 1000)+"提交完成").sendToTarget();
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_AUDIO_SUBMIT, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 请求批改
	 */
	public void audioCharge(final String user_id,final String record_id,final String phone_number,final String title,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", user_id,true);
					params.add("record_id", record_id,true);
					params.add("phone_number", phone_number,true);
					params.add("title", title,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_CHARGE, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_CHARGE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 请求批改
	 */
	public void tips(final String title,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("title", title,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_TIPS, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_TIPS, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 听力原文
	 */
	public void tingLiYuanWen(final String title,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("title", title,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_TingLi, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_TingLi, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 请求批改
	 */
	public void audioCharges(final String user_id,final String phone_number,final Object []record_id,final Object []title,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", user_id,true);
					params.add("phone_number", phone_number,true);
					
					String str="";
					for(int i=0;i<record_id.length;i++)
					{
						records r=new records();
						r.record_id=record_id[i].toString();
						r.title=title[i].toString();
						str=str+r+",";
					}
					if(str.length()>0)
					{
						str=str.substring(0, str.length()-1);
					}
					str="["+str+"]";
					params.add("records", str,true);
					//params.add("titles", title,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_MAnY_CHARGE, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_MAnY_CHARGE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	class records
	{
		@Override
		public String toString() {
			// TODO Auto-generated method stub
			return "{\"record_id\":\""+record_id+"\",\"title\":\""+title+"\"}";
		}
		public String record_id;
		public String title;
	}
	/*
	 * 我的批改
	 */
	public void getAllRevisers(final String user_id,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", user_id,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_MY_REVISERS, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_GET_ALL_REVISERS, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 充值
	 */
	public void chongZhi(final String user_id,final String phone_number,final int amount,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", user_id,true);
					params.add("phone_number", phone_number,true);
					params.add("amount", amount,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_CHONGZHI, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_CHONGZHI, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 评论
	 */
	public void commentRevise(final String xiaofei_id,final String feedback_rate,final String feedback_msg,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("xiaofei_id", xiaofei_id,true);
					params.add("feedback_rate", feedback_rate,true);
					params.add("feedback_msg", feedback_msg,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_FEEDBACK, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_FEEDBACK, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 根据xiaofei_id获取一条消费记录
	 */
	public void getOneXiaoFei(final String xiaofei_id,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("xiaofei_id", xiaofei_id,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_ONE_CHARGE, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_ONE_CHARGE, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 获取教师
	 */
	public void getTeachers(final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", "1",true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_TEACHERS, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_Teacher, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	/*
	 * 排行榜
	 */
	public void getPaihangbang(final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("user_id", "1",true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_RANKING, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_RANKING, mRes).sendToTarget();
					}
				} catch (Exception er) {
					er.printStackTrace();
				}
			}
		}.start();
	}
	/*
	 * 排行榜
	 */
	public void getPaihangbangOthers(final String title,final String record_id,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("title", title,true);
					params.add("record_id", record_id,true);
					String mRes = request(MiaoApi.GetBaseURL(), GOLD_RANKING_OTHERS, params,1);
					if (handler != null) {
						handler.obtainMessage(Constants.GOLD_RANKING_OTHERS, mRes).sendToTarget();
					}
				} catch (Exception er) {
					er.printStackTrace();
				}
			}
		}.start();
	}
}
